/*
 * OrderDetailStatusListItem.java
 * business
 *
 * Created by SunDing on 2016/9/9.
 *
 * Copyright (c) 2016年 yidiandao. All rights reserved.
 */

package com.yidiandao.business.ui.widget.listview.displaylistitem;

import android.content.ClipboardManager;
import android.content.Context;
import android.text.TextUtils;
import android.view.View;

import com.yidiandao.business.R;
import com.yidiandao.business.data.bean.Order;
import com.yidiandao.business.data.response.OrderDetailResponse;
import com.yidiandao.business.ui.widget.dialog.CallPhoneDialog;
import com.yidiandao.business.ui.widget.listview.DisplayListItem;
import com.yidiandao.business.ui.widget.listview.viewholder.OrderDetailMessageHolder;
import com.yidiandao.business.utils.UIUtils;

import java.util.List;

/**
 * 订单详情 发票信息
 */
public class OrderDetailMessageListItem
        extends DisplayListItem<OrderDetailMessageHolder, OrderDetailResponse.Data> {

    public OrderDetailMessageListItem(OrderDetailResponse.Data s) {
        super(s);
    }

    @Override
    public void onShow(final Context context, OrderDetailMessageHolder holder) {
        //支付方式
        holder.mTvPayWay.setText(data.getOrder().getPayName());
        //配送方式
        holder.mTvLogisticsWay.setText(data.getOrder().getDeliveryInfo());
        //发票
        String invPayee = data.getOrder().getInvPayee();
        holder.mTvInvoice.setText(
                TextUtils.isEmpty(invPayee)
                        ? UIUtils.getString(R.string.order_detail_invoice_no)
                        : invPayee);
        final List<Order.PayDescBean> payDesc = data.getOrder().getPayDesc();
        if(null!=payDesc&&payDesc.size()!=0) {
            //户名
            holder.mLlUserName.setVisibility(!TextUtils.isEmpty(payDesc.get(0).getDesc()) ? View.VISIBLE : View.GONE);
            holder.mUserName.setText(payDesc.get(0).getDesc());
            //账户
            holder.mLlBankNum.setVisibility(!TextUtils.isEmpty(payDesc.get(2).getDesc()) ? View.VISIBLE : View.GONE);
            holder.mTvBankNum.setText(payDesc.get(2).getDesc());
            //开户行
            holder.mLlBakName.setVisibility(!TextUtils.isEmpty(payDesc.get(1).getDesc()) ? View.VISIBLE : View.GONE);
            holder.mTvBankName.setText(payDesc.get(1).getDesc());
            //联行号
            holder.mLlBankCon.setVisibility(!TextUtils.isEmpty(payDesc.get(3).getDesc()) ? View.VISIBLE : View.GONE);
            holder.mTvBankConName.setText(payDesc.get(3).getDesc());
            //识别码
            holder.mLlIdentifyCode.setVisibility(!TextUtils.isEmpty(data.getOrder().getBankPaySn()) ? View.VISIBLE : View.GONE);
            holder.mTvIdentifyCode.setText(UIUtils.getString(R.string.order_identify_code, data.getOrder().getBankPaySn()));
        }
        //买家留言
        String orderLog = data.getOrder().getOrderLog();
        holder.mTvMessage.setText(TextUtils.isEmpty(orderLog) ? "无" : orderLog);
        final String servicePhone = data.getOrder().getServicePhone();
        holder.mTvPhone.setText(servicePhone);
        holder.mTvPhone.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                CallPhoneDialog callPhoneDialog = new CallPhoneDialog(context);
                callPhoneDialog.show();
                callPhoneDialog.setPhoneNum(servicePhone);
            }
        });
        holder.mCopyBankName.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String desc = payDesc.get(0).getDesc();
                copyContent(desc);
            }
        });
        holder.mCopyBankNum.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String desc = payDesc.get(2).getDesc();
                copyContent(desc);
            }
        });
        holder.mCopyIdentifyCode.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String bankPaySn = data.getOrder().getBankPaySn();
                copyContent(bankPaySn);
            }
        });

    }

    private void copyContent(String desc) {
        ClipboardManager cmb =
                (ClipboardManager)
                        UIUtils.getContext().getSystemService(Context.CLIPBOARD_SERVICE);
        cmb.setText(desc);
        UIUtils.showToast("复制成功");
    }

    @Override
    public String getDisplayItemTag() {
        return OrderDetailMessageListItem.class.getSimpleName();
    }

    @Override
    public Class<OrderDetailMessageHolder> getViewHolderClazz() {
        return OrderDetailMessageHolder.class;
    }
}
